const express = require('express');
const router = express.Router();
const { 
  searchAll,
  searchUsers
} = require('../controllers/searchController');
const { protect } = require('../middlewares/authMiddleware');

/**
 * @swagger
 * /search/search-All:
 *   get:
 *     summary: 广泛搜索功能（包括帖子和用户昵称）
 *     tags: [Search]
 *     description: 根据关键字搜索帖子和用户昵称
 *     parameters:
 *       - in: query
 *         name: keyword
 *         required: true
 *         schema:
 *           type: string
 *         description: 搜索关键字
 *     responses:
 *       200:
 *         description: 返回搜索到的帖子和用户
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 posts:
 *                   type: array
 *                   items:
 *                     $ref: '#/components/schemas/Post'
 *                 users:
 *                   type: array
 *                   items:
 *                     $ref: '#/components/schemas/User'
 *       400:
 *         description: 关键字不能为空
 *       500:
 *         description: 搜索失败，请稍后重试
 */
router.get('/search-All', protect, searchAll);

/**
 * @swagger
 * /search/search-users:
 *   get:
 *     summary: 单独搜索用户功能
 *     tags: [Search]
 *     description: 根据关键字搜索用户昵称
 *     parameters:
 *       - in: query
 *         name: keyword
 *         required: true
 *         schema:
 *           type: string
 *         description: 搜索关键字
 *     responses:
 *       200:
 *         description: 返回搜索到的用户
 *         content:
 *           application/json:
 *             schema:
 *               type: array
 *               items:
 *                 $ref: '#/components/schemas/User'
 *       400:
 *         description: 关键字不能为空
 *       500:
 *         description: 搜索用户失败，请稍后重试
 */
router.get('/search-users', protect, searchUsers);

module.exports = router;